home *** CD-ROM | disk | FTP | other *** search
/ PC/CD Gamer UK 120 / CD Gamer Issue 120 (March 2003) (Disc 2).ISO / mods / Q2_Codered / codeRED1_0.exe / Data1.cab / M_war_machine.c < prev    next >
Encoding:
C/C++ Source or Header  |  2002-12-20  |  10.7 KB  |  438 lines

  1. /*
  2. ==============================================================================
  3.  
  4. Martian War Machine
  5.  
  6. ==============================================================================
  7. */
  8.  
  9. #include "g_local.h"
  10. #include "m_war_machine.h"
  11.  
  12.  
  13. static int sound_pain;
  14. static int sound_die;
  15. static int sound_idle;
  16. static int sound_punch;
  17. static int sound_sight;
  18. static int sound_search;
  19.  
  20. void warmach_sight (edict_t *self, edict_t *other)
  21. {
  22.     gi.sound (self, CHAN_VOICE, sound_sight, 1, ATTN_NORM, 0);
  23. }
  24.  
  25. void warmach_search (edict_t *self)
  26. {
  27.     gi.sound (self, CHAN_VOICE, sound_search, 1, ATTN_NORM, 0);
  28. }
  29.  
  30.  
  31. void warmach_fidget (edict_t *self);
  32. mframe_t warmach_frames_stand [] =
  33. {
  34.     ai_stand, 0, NULL,
  35.     ai_stand, 0, NULL,
  36.     ai_stand, 0, NULL,
  37.     ai_stand, 0, NULL,
  38.     ai_stand, 0, NULL,
  39.     ai_stand, 0, NULL,
  40.     ai_stand, 0, NULL,
  41.     ai_stand, 0, NULL
  42.     
  43. };
  44. mmove_t warmach_move_stand = {FRAME_stand01, FRAME_stand08, warmach_frames_stand, NULL};
  45.  
  46. void war_stomp_right (edict_t *self)
  47. {
  48.     int        i;
  49.     edict_t    *e;
  50.     vec3_t    forward, right;
  51.     vec3_t    start;
  52.  
  53.     for (i=1, e=g_edicts+i; i < globals.num_edicts; i++,e++)
  54.     {
  55.         if (!e->inuse)
  56.             continue;
  57.         if (!e->client)
  58.             continue;
  59.         if (!e->groundentity)
  60.             continue;
  61.  
  62.         e->groundentity = NULL;
  63.         e->velocity[0] += crandom()* 50;
  64.         e->velocity[1] += crandom()* 50;
  65.         e->velocity[2] += crandom()* 100;
  66.     }
  67.     
  68.     AngleVectors (self->s.angles, forward, right, NULL);
  69.     VectorCopy (self->s.origin, start);
  70.  
  71.     //start[2] = start[2] - 16;
  72.         
  73.     right[0] = right[0] * 105;
  74.     right[1] = right[1] * 105;
  75.     forward[0] = forward[0] * 10;
  76.     forward[1] = forward[1] * 10;
  77.  
  78.     VectorAdd(start, forward, start);
  79.     VectorAdd(start, right, start);
  80.  
  81.     gi.WriteByte (svc_temp_entity);
  82.     gi.WriteByte (TE_EXPLOSION2);
  83.     gi.WritePosition (start);
  84.     gi.multicast (start, MULTICAST_PVS);
  85.  
  86.     gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
  87. }
  88.  
  89. void war_stomp_left (edict_t *self)
  90. {
  91.     int        i;
  92.     edict_t    *e;
  93.     vec3_t    forward, right;
  94.     vec3_t    start;
  95.  
  96.     for (i=1, e=g_edicts+i; i < globals.num_edicts; i++,e++)
  97.     {
  98.         if (!e->inuse)
  99.             continue;
  100.         if (!e->client)
  101.             continue;
  102.         if (!e->groundentity)
  103.             continue;
  104.  
  105.         e->groundentity = NULL;
  106.         e->velocity[0] += crandom()* 50;
  107.         e->velocity[1] += crandom()* 50;
  108.         e->velocity[2] += crandom()* 100;
  109.     }
  110.     
  111.     AngleVectors (self->s.angles, forward, right, NULL);
  112.     VectorCopy (self->s.origin, start);
  113.     
  114.     //start[2] = start[2] - 16;
  115.     
  116.     right[0] = right[0] * -100;
  117.     right[1] = right[1] * -100;
  118.  
  119.     forward[0] = forward[0] * 15;
  120.     forward[1] = forward[1] * 15;
  121.  
  122.     VectorAdd(start, forward, start);
  123.     
  124.     VectorAdd(start, right, start);
  125.  
  126.     gi.WriteByte (svc_temp_entity);
  127.     gi.WriteByte (TE_EXPLOSION2);
  128.     gi.WritePosition (start);
  129.     gi.multicast (start, MULTICAST_PVS);
  130.  
  131.     gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
  132.  
  133. }
  134. void war_stomp_middle (edict_t *self)
  135. {
  136.     int        i;
  137.     edict_t    *e;
  138.     vec3_t    forward, right;
  139.     vec3_t    start;
  140.  
  141.     for (i=1, e=g_edicts+i; i < globals.num_edicts; i++,e++)
  142.     {
  143.         if (!e->inuse)
  144.             continue;
  145.         if (!e->client)
  146.             continue;
  147.         if (!e->groundentity)
  148.             continue;
  149.  
  150.         e->groundentity = NULL;
  151.         e->velocity[0] += crandom()* 50;
  152.         e->velocity[1] += crandom()* 50;
  153.         e->velocity[2] += crandom()* 100;
  154.     }
  155.     
  156.     AngleVectors (self->s.angles, forward, right, NULL);
  157.     VectorCopy (self->s.origin, start);
  158.     
  159.     //start[2] = start[2] - 16;
  160.     
  161.     forward[0] = forward[0] * 185;
  162.     forward[1] = forward[1] * 185;
  163.  
  164.     VectorAdd(start, forward, start);
  165.     
  166.     VectorAdd(start, right, start);
  167.  
  168.     gi.WriteByte (svc_temp_entity);
  169.     gi.WriteByte (TE_EXPLOSION2);
  170.     gi.WritePosition (start);
  171.     gi.multicast (start, MULTICAST_PVS);
  172.  
  173.     gi.sound (self, CHAN_VOICE, sound_die, 1, ATTN_NORM, 0);
  174. }
  175.  
  176. void warmach_stand (edict_t *self)
  177. {
  178.     self->monsterinfo.currentmove = &warmach_move_stand;
  179. }
  180.  
  181.  
  182.  
  183.  
  184. mframe_t warmach_frames_run1 [] =
  185. {
  186.     ai_run, 0, NULL,
  187.     ai_run, 0, NULL,
  188.     ai_run, 0, NULL,
  189.     ai_run, 0, NULL,
  190.     ai_run, 0, NULL,
  191.     ai_run, 0, NULL,
  192.     ai_run, 0, war_stomp_middle,
  193.     ai_run, 25, NULL,
  194.     ai_run, 30, war_stomp_right,
  195.     ai_run, 25, NULL,
  196.     ai_run, 20, NULL,
  197.     ai_run, 15, war_stomp_left
  198. };
  199. mmove_t warmach_move_run1 = {FRAME_walk01, FRAME_walk12, warmach_frames_run1, NULL};
  200.  
  201. void warmach_run (edict_t *self)
  202. {
  203.     if (self->monsterinfo.aiflags & AI_STAND_GROUND)
  204.         self->monsterinfo.currentmove = &warmach_move_stand;
  205.     else
  206.         self->monsterinfo.currentmove = &warmach_move_run1;
  207.  
  208.     gi.sound (self, CHAN_WEAPON, sound_idle, 1, ATTN_NORM, 0);
  209. }
  210.  
  211. void warmach_laser_right (edict_t *self)
  212. {
  213.     vec3_t    forward, right;
  214.     vec3_t    start;
  215.     vec3_t    end;
  216.     vec3_t    dir;
  217.     vec3_t    from;
  218.     int        damage = 20;
  219.     int        flash_number = MZ2_MAKRON_BFG;
  220.     trace_t tr;
  221.  
  222.     AngleVectors (self->s.angles, forward, right, NULL);
  223.     G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
  224.     VectorCopy (self->s.origin, start);
  225.     VectorCopy (self->enemy->s.origin, end);
  226.     end[2] += self->enemy->viewheight;
  227.     VectorSubtract (end, start, dir);
  228.     
  229.     right[0] = right[0] * 95;
  230.     right[1] = right[1] * 95;
  231.     start[2] = start[2] + 270;
  232.  
  233.     VectorAdd(start, right, start);
  234.  
  235.     end[2] = end[2] - 32;
  236.  
  237.     VectorCopy (start, from);
  238.     tr = gi.trace (from, NULL, NULL, end, self, MASK_SHOT);      
  239.     VectorCopy (tr.endpos, from);
  240.  
  241.     gi.WriteByte (svc_temp_entity);
  242.     gi.WriteByte (TE_SHOTGUN);
  243.     gi.WritePosition (start);
  244.     gi.WritePosition (end);
  245.     gi.multicast (start, MULTICAST_PHS); 
  246.     gi.sound (self, CHAN_VOICE, sound_punch, 1, ATTN_NORM, 0);
  247.     
  248.     if ((tr.ent != self) && (tr.ent->takedamage))
  249.         T_Damage (tr.ent, self, self, dir, tr.endpos, tr.plane.normal, damage, 0, 0, MOD_HYPERBLASTER);
  250.     else if (!((tr.surface) && (tr.surface->flags & SURF_SKY)))
  251.     {  
  252.         gi.WriteByte (svc_temp_entity);
  253.         gi.WriteByte (TE_SCREEN_SPARKS);
  254.         gi.WritePosition (tr.endpos);
  255.         gi.WriteDir (tr.plane.normal);
  256.         gi.multicast (self->s.origin, MULTICAST_PVS);
  257.     }
  258. }
  259.  
  260. void warmach_laser_left (edict_t *self)
  261. {
  262.     vec3_t    forward, right;
  263.     vec3_t    start;
  264.     vec3_t    end;
  265.     vec3_t    dir;
  266.     vec3_t    from;
  267.     int        damage = 20;
  268.     int        flash_number = MZ2_MAKRON_BFG;
  269.     trace_t tr;
  270.  
  271.     AngleVectors (self->s.angles, forward, right, NULL);
  272.     G_ProjectSource (self->s.origin, monster_flash_offset[flash_number], forward, right, start);
  273.     VectorCopy (self->s.origin, start);
  274.     VectorCopy (self->enemy->s.origin, end);
  275.     end[2] += self->enemy->viewheight;
  276.     VectorSubtract (end, start, dir);
  277.     
  278.     right[0] = right[0] * -100;
  279.     right[1] = right[1] * -100;
  280.     start[2] = start[2] + 280;
  281.  
  282.     VectorAdd(start, right, start);
  283.  
  284.     end[2] = end[2] - 32;
  285.  
  286.     VectorCopy (start, from);
  287.     tr = gi.trace (from, NULL, NULL, end, self, MASK_SHOT);      
  288.     VectorCopy (tr.endpos, from);
  289.  
  290.     gi.WriteByte (svc_temp_entity);
  291.     gi.WriteByte (TE_SHOTGUN);
  292.     gi.WritePosition (start);
  293.     gi.WritePosition (end);
  294.     gi.multicast (start, MULTICAST_PHS); 
  295.     gi.sound (self, CHAN_VOICE, sound_punch, 1, ATTN_NORM, 0);
  296.     
  297.     if ((tr.ent != self) && (tr.ent->takedamage))
  298.         T_Damage (tr.ent, self, self, dir, tr.endpos, tr.plane.normal, damage, 0, 0, MOD_HYPERBLASTER);
  299.     else if (!((tr.surface) && (tr.surface->flags & SURF_SKY)))
  300.     {  
  301.         gi.WriteByte (svc_temp_entity);
  302.         gi.WriteByte (TE_SCREEN_SPARKS);
  303.         gi.WritePosition (tr.endpos);
  304.         gi.WriteDir (tr.plane.normal);
  305.         gi.multicast (self->s.origin, MULTICAST_PVS);
  306.     }
  307. }    
  308.  
  309. mframe_t warmach_frames_attack_laser [] =
  310. {
  311.     ai_charge, 0, NULL,
  312.     ai_charge, 0, NULL,
  313.     ai_charge, 0, NULL,
  314.     ai_charge, 0, NULL,
  315.     ai_charge, 0, NULL,
  316.     ai_charge, 0, NULL,
  317.     ai_charge, 0, warmach_laser_right,
  318.     ai_charge, 0, NULL,
  319.     ai_charge, 0, NULL,
  320.     ai_charge, 0, warmach_laser_left,
  321.     ai_charge, 0, NULL,
  322.     ai_charge, 0, NULL
  323. };
  324.     
  325. mmove_t warmach_move_attack_laser = {FRAME_atta01, FRAME_atta12, warmach_frames_attack_laser, warmach_run};
  326.  
  327.  
  328. void warmach_melee (edict_t *self)
  329. {
  330.     self->monsterinfo.currentmove = &warmach_move_attack_laser;
  331. }
  332.  
  333. void warmach_pain (edict_t *self, edict_t *other, float kick, int damage)
  334. {
  335.     gi.sound (self, CHAN_VOICE, sound_pain, 1, ATTN_NORM, 0);
  336. }
  337.  
  338. void warmach_die (edict_t *self, edict_t *inflictor, edict_t *attacker, int damage, vec3_t point)
  339. {
  340.     int        n, spd;
  341.     vec3_t start, org;
  342.  
  343.     // tower of fire code here (will add body parts flying next)
  344.     VectorCopy (self->s.origin, start);
  345.     for (n = 1; n < 5; n++)
  346.     {
  347.         start[2] = start[2] + 64;
  348.         gi.WriteByte (svc_temp_entity);
  349.         gi.WriteByte (TE_EXPLOSION1);
  350.         gi.WritePosition (start);
  351.         gi.multicast (start, MULTICAST_PVS);
  352.     }
  353. /*
  354.     for (n = 0; n < 2; n++)
  355.     {
  356.         spd = 5;
  357.         org[0] = self->s.origin[0] + crandom() * 5.0;
  358.         org[1] = self->s.origin[1] + crandom() * 5.0;
  359.         org[2] = self->s.origin[2] + crandom() * 5.0;
  360.         ThrowDebris (self, "models/objects/gibs/war_tent/tris.md2", spd, org);
  361.     }
  362. */
  363.     for (n = 0; n < 3; n++)
  364.     {
  365.         spd = 5;
  366.         org[0] = self->s.origin[0] + crandom() * 5.0;
  367.         org[1] = self->s.origin[1] + crandom() * 5.0;
  368.         org[2] = self->s.origin[2] + crandom() * 5.0;
  369.         ThrowDebris (self, "models/objects/gibs/war_leg/tris.md2", spd, org);
  370.     }
  371.  
  372.     ThrowHead (self, "models/objects/gibs/war_body/tris.md2", damage, GIB_METALLIC, 0);
  373.  
  374.     self->deadflag = DEAD_DEAD;
  375.     self->takedamage = DAMAGE_NO;
  376.     VectorSet (self->mins, -32, -32, 0);
  377.     VectorSet (self->maxs, 32, 32, 8);
  378.     self->movetype = MOVETYPE_TOSS;
  379.     self->nextthink = 0;
  380.     self->think = NULL;
  381. }
  382.  
  383. /*QUAKED monster_warmach (1 .5 0) (-16 -16 -24) (16 16 32) Ambush Trigger_Spawn Sight
  384. */
  385. void SP_monster_warmach (edict_t *self)
  386. {
  387.     if (deathmatch->value)
  388.     {
  389.         G_FreeEdict (self);
  390.         return;
  391.     }
  392.  
  393.     // pre-caches
  394.     sound_pain  = gi.soundindex ("martian/robotmove.wav");
  395.     
  396.  
  397.     sound_punch = gi.soundindex ("martian/shoot1.wav");
  398.     sound_search = gi.soundindex ("world/engine3.wav");
  399.     sound_sight = gi.soundindex ("world/engine3.wav");
  400.       
  401.     sound_idle = gi.soundindex ("world/engine3.wav");
  402.     sound_die = gi.soundindex ("martian/step.wav");
  403.  
  404.     self->s.modelindex = gi.modelindex("models/monsters/martian_war/tris.md2");
  405.     VectorSet (self->mins, -48, -48, 0);
  406.     VectorSet (self->maxs, 48, 48, 256);
  407.     self->movetype = MOVETYPE_STEP;
  408.     self->solid = SOLID_BBOX;
  409.     self->s.skinnum = 0;
  410.  
  411.     self->max_health = 600;        // for testing 
  412.     self->health = self->max_health;
  413.     self->gib_health = 0;
  414.     self->mass = 2450;
  415.  
  416.     self->classname = "monster_ambass";
  417.  
  418.     self->pain = warmach_pain;
  419.     self->die = warmach_die;
  420.  
  421.     self->monsterinfo.stand = warmach_stand;
  422.     self->monsterinfo.walk = warmach_run;
  423.     self->monsterinfo.run = warmach_run;
  424.     self->monsterinfo.dodge = NULL;
  425.     self->monsterinfo.attack = warmach_melee;
  426.     self->monsterinfo.melee = warmach_melee;
  427.     self->monsterinfo.sight = warmach_sight;
  428.     self->monsterinfo.search = warmach_search;
  429.  
  430.     self->monsterinfo.currentmove = &warmach_move_stand;
  431.     self->monsterinfo.scale = MODEL_SCALE;
  432.  
  433.     gi.linkentity (self);
  434.  
  435.     walkmonster_start (self);
  436. }
  437.  
  438.